package com.example.kotlindemo.范性

import android.animation.Animator
import android.animation.ValueAnimator
import androidx.core.animation.addListener
import java.lang.reflect.ParameterizedType

object Generic {
    //匿名内部类获得泛型信息
    open class InnerClass<T>

    @JvmStatic
    fun main(args:Array<String>){
        val innerClass = object : InnerClass<Int>(){

        }

        val typeClass = innerClass.javaClass.genericSuperclass
        println(typeClass)

        if(typeClass is ParameterizedType){
            println(typeClass.actualTypeArguments[0])
        }

        //inline 函数可以在运行时期获取参数类型
        val arrays = arrayOf<Int>(1,2,3)
        val arrays2 = arrayOf<String>("1","2","3")

        println(arrays.javaClass)
        println(arrays2.javaClass)

        //reifiled 解决范性擦除 让type保留在运行时
        doSomething(1)

        val animalPrinter = AnimalPrinter()
        animalPrinter.print(Dog())


        val animator = ValueAnimator.ofInt(0,100)
//        animator.addListener(object :Animator.AnimatorListener{
//            override fun onAnimationStart(animation: Animator) {
//                TODO("Not yet implemented")
//            }
//
//            override fun onAnimationEnd(animation: Animator) {
//                TODO("Not yet implemented")
//            }
//
//            override fun onAnimationCancel(animation: Animator) {
//                TODO("Not yet implemented")
//            }
//
//            override fun onAnimationRepeat(animation: Animator) {
//                TODO("Not yet implemented")
//            }
//
//        })
        animator.addListener(

        )



    }


    inline fun <reified T> doSomething(value: T) {
        println("Doing something with value: $value")                 // OK
        println("Doing something with type: ${T::class.simpleName}")  // Error
    }

//
//    inline fun<reified T:Any> Gson.formJson(json:String):T =
//        Gson().fromJson(json,T::class.java)


    open class Anmial{

    }


    class Dog:Anmial(){

    }


    abstract class Printer<in E>{
        abstract fun print(value: E): @UnsafeVariance E
    }
    class AnimalPrinter:Printer<Anmial>(){
        override fun print(value: Anmial):  Anmial{
            println()
            return Anmial()
        }
    }

    class DogPrinter:Printer<Dog>(){
        override fun print(value: Dog): Dog {
            println()
            return Dog()
        }
    }



//    fun<T : Dog> sum(vararg param:T) = param.sumOf {  }


    open class A
    interface B
    class C<T>(var param:Class<T>) where T:A, T:B

    fun print(list:MutableList<*>){
        println(list[0])
    }

    //Any?



}